<?php
/**
 * Coffee Framework

 * @category   CF
 * @package    CF_db
 * @author     그네 <Jung Sik, Park> <ccooffeee at hotmail dot com>
 * @copyright  Copyright (c) 2009 Jung Sik, Park <ccooffeee at hotmail dot com>
 * @license    doc/LICENSE    Based New BSD License
 * @version    $Id: db.php,v 0.1.3 2010/08/09 ccooffeee Exp $

 * LICENSE

 * 본 프로그램은 New BSD License 를 기본으로 하고 있지만 약간 다른 제약조건을 가지고 있습니다. 
 * 함께 제공된 license file 인  doc/LICENSE 를 꼭 확인하시길 바랍니다.

 * This Source is subject to the New BSD License with SOME CONSTRAINT that is boudled
 * with this package in the file doc/LICENSE 
 */


require_once __DIR__.'/abstract.php';


class CF_db_sqlite extends CF_db_abstract
{

// {{{ string escape (string)
	public function escape($str)
	{
		if($this->_isQuoted())
			$str = stripslashes($str);

		return sqlite_escape_string($str);
	}
// }}}


// {{{ protected methods
	// {{{ void connect ()
	protected function connect() {
		if($this->dao !== null) return;
		if($this->config === null) return;

		$dsn = $this->configToDsn();

		try {
			$this->dao = new PDO ($dsn);
		} Catch (PDOException $e) {
			throw new CF_db_exception ($e->getMessage(), $e->getCode(), $e);
		}
	}
	// }}}
	// {{{ string configToDsn ()
	protected function configToDsn() {
		if($this->config === null)
			return null;

		if(!isset($this->config['driver']) || !$this->config['driver'])
			return null;

		$dsn = $this->config['driver'].':';
		$dsn .= $this->config['name'];

		return $dsn;
	}
	// }}}
	// {{{ void _checkOption()
	protected function _checkOption() {
		if(!isset($this->config['driver']) || !$this->config['driver'])
			throw new CF_db_exception ("Configure must have a 'driver' key that names the database driver name");
		if(!isset($this->config['name']) || !$this->config['name'])
			throw new CF_db_exception ("Configure must have a 'name' key that names the database name");
	}
	// }}}
// }}}
}

// vim: ts=4 sw=4 fdm=marker
?>
